package com.gen;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class CodeGenerator {

    public static void main(String[] args) {
        // 1. 数据源配置
        DataSourceConfig dsc = new DataSourceConfig.Builder(
                "jdbc:mysql://8.152.205.18:12777/db1?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai",
                "root",
                "gshbttttt"
        ).build();

        // 2. 全局配置
        GlobalConfig gc = new GlobalConfig.Builder()
                .outputDir(System.getProperty("user.dir") + "/src/main/java")
                .author("wangjinliang")
                .build();

        // 3. 包配置
        PackageConfig pc = new PackageConfig.Builder()
                .parent("com.gen.dao")
                .entity("domain")
                .mapper("mapper")
                .build();

        // 4. 策略配置（重点：生成哪些表）
        StrategyConfig strategy = new StrategyConfig.Builder()
                .addInclude("t_user", "t_paper")
                .addTablePrefix("t_")
                .entityBuilder()
                .naming(NamingStrategy.underline_to_camel)
                .columnNaming(NamingStrategy.underline_to_camel)
                .enableLombok()
                .mapperBuilder()
                .enableMapperAnnotation()
                .enableBaseResultMap()
                .build();

        // 5. 执行生成
        new AutoGenerator(dsc)
                .global(gc)
                .packageInfo(pc)
                .strategy(strategy)
                .execute();
    }
}
